/**
 * Created by Administrator on 2017/8/22.
 */
"use strict";
let express=require('express');
let session=require('express-session');
var compression = require('compression')
let formidable=require('formidable');
let cors=require('cors');
let router=require('./router/router');
let app=express();

//设置模板引擎
app.set('view engine', 'ejs');
//设置静态资源目录
app.use(express.static('./public'));
//设置跨域
app.use(cors());
//开启gzip
app.use(compression());
//设置session
app.set('trust proxy', 1);
//设置session配置
app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true,
    cookie: { secure: false }
}));
//首页
app.get('/',function(req,res){
    res.render('index',{
        page:'index'
    });
});
/*首页*/
app.post('/getautoPlay',router.getautoPlay);
app.post('/getrmxsBook',router.getrmxsBook);
app.post('/getrxbBook',router.getrxbBook);
app.post('/getfybBook',router.getfybBook);
app.post('/getypbBook',router.getypbBook);
app.post('/gettjbBook',router.gettjbBook);
app.post('/getxsqxBook',router.getxsqxBook);
app.post('/getqxwbBook',router.getqxwbBook);
app.post('/getxsmfBook',router.getxsmfBook);
app.post('/getxhqhBook',router.getxhqhBook);
app.post('/getxxwxBook',router.getxxwxBook);
app.post('/getdszcBook',router.getdszcBook);
app.post('/getlsjsBook',router.getlsjsBook);
app.post('/getyxtyBook',router.getyxtyBook);
app.post('/getkhlyBook',router.getkhlyBook);
app.post('/getecyBook',router.getecyBook);
/*首页*/

//注册页
app.get('/register',router.register);
//登录页
app.get('/login',router.login);
//登陆验证码
app.get('/loginCode',router.loginCode);
//注册验证码
app.get('/recode',router.recode);
/*登录注册*/
//注册验证验证码
app.post('/dorecode',router.doRecode);
//登录提交
app.post("/login",router.doLogin);
//登陆验证验证码
app.post('/doLoginCode',router.doLoginCode);
//注册提交
app.post("/register",router.doRegister);
/*登录注册*/

//分类
app.get('/category/detail/:catid/:subid/:type',router.categoryDefail);
app.get('/category/male/:catid/:type',router.categoryMale);
app.get('/category/:key',router.categoryKey);
app.post('/getCateSubBook',router.getCateSubBook);
app.post('/getCateBook',router.getCateBook);
/*分类*/
app.post('/getmaleCate',router.getmaleCate);
/*分类*/

//排行榜
app.get('/rank/:key',router.rankKey);
app.get('/rank/male/:key',router.rankMaleKey);
/*排行榜*/
app.post('/getProminent',router.getProminent);
app.post('/getRankBookCount',router.getRankBookCount);
app.post('/getRankBook',router.getRankBook);
/*排行榜*/

//免费
app.get('/free/:key',function(req,res){
    let session=false;
    if(req.session.username){
        session=true;
    }
    if(req.params.key=="male"){
        res.render('free',{
            page:'male',
            session:session
        });
    }else if(req.params.key=="female"){
        res.render('free',{
            page:'female',
            session:session
        });
    }else{
        res.render('error',{page:'error'});
    }
});
//完本
app.get('/finish/:key',function(req,res){
    let session=false;
    if(req.session.username){
        session=true;
    }
    if(req.params.key=="male"){
        res.render('finish',{
            page:'male',
            session:session
        });
    }else if(req.params.key=="female"){
        res.render('finish',{
            page:'female',
            session:session
        });
    }else{
        res.render('error',{page:'error'});
    }
});
//书
app.get('/book/:key',router.bookKey);
/*书*/
app.post('/getbookInfo',router.getbookInfo);
app.post('/getuserHeadimg',router.getuserHeadimg);
app.post('/getariaFansNum',router.getariaFansNum);
app.post('/getariaFansNums',router.getariaFansNums);
app.post('/getBookTicket',router.getBookTicket);
app.post('/getuserTicket',router.getuserTicket);
app.post('/setBookShelf',router.setBookShelf);
app.post('/getBookshelfType',router.getBookshelfType);
app.post('/getBookClickNum',router.getBookClickNum);
/*书*/

//书评
app.get('/book/forum/:key',router.forumKey);
//书评详情
app.get('/book/thread/:key',router.threadKey);
//评论
app.get('/book/comment/:key',router.commentKey);
/*书评*/
app.post('/getforumList',router.getforumList);
app.post('/getforumCount',router.getforumCount);
app.post('/addForumCnt',router.addForumCnt);
app.post('/getforumHot',router.getforumHot);
app.post('/getforumHotList',router.getforumHotList);
app.post('/getForumInfo',router.getForumInfo);
app.post('/getForumUserCount',router.getForumUserCount);
app.post('/getForumUserList',router.getForumUserList);
app.post('/addForumUserCnt',router.addForumUserCnt);
/*书评*/

//目录
app.get('/book/catalog/:key',router.catalogKey);
/*目录*/
app.post('/getChapter',router.getChapter);
app.post('/setBookChapter',router.setBookChapter);
/*目录*/

//书籍阅读
app.get('/look/:key',router.lookKey);
/*书籍阅读*/
app.post("/getChapterObj",router.getChapterObj);
app.post("/getChapterText",router.getChapterText);
/*书籍阅读*/

//搜索
app.get('/search',router.search);
/*搜索*/
//热门搜索
app.post('/allSearch',router.allSearch);
//索取搜索的书籍
app.post('/getSearchBook',router.getSearchBook);
//获取输入框键盘按下的书籍
app.post('/getSearchBookKeyUp',router.getSearchBookKeyUp);
//设置热门搜索
app.post('/setHotsearch',router.setHotsearch);
/*搜索*/

//我的书架历史记录
app.get('/bookshelf/:key',router.bookshelfKey);
/*书架*/
//登录的我的书架
app.post('/bookcase',router.bookcase);
app.post('/removeBookcase',router.removeBookcase);
app.post('/addBookShelf',router.addBookShelf);
app.post('/moveBookShelf',router.moveBookShelf);
/*书架*/

//个人中心
app.get('/user',router.user);
//月票推荐票
app.get('/user/ticket/:key',router.ticketKey);
//起点豆
app.get("/user/account",router.userAccount);
//我的消息
app.get("/user/msg",router.userMsg);
//我的信息
app.get("/user/info",router.userInfo);
//上传头像
app.get("/user/info/headimg",router.userInfoHeadImg);

/*个人用户*/
app.post('/addSetMonth',router.addSetMonth);
app.post('/addSetRecomm',router.addSetRecomm);
app.post('/addSetReward',router.addSetReward);
app.post('/getMonthList',router.getMonthList);
app.post('/getRecommList',router.getRecommList);
app.post('/getRewardList',router.getRewardList);
app.post('/updateHeadImg',router.updateHeadImg);
app.post('/setUserInfo',router.setUserInfo);
app.post('/getMsgUserCount',router.getMsgUserCount);
app.post('/getMsgUserPinglun',router.getMsgUserPinglun);
app.post('/getMsgUserSubCount',router.getMsgUserSubCount);
app.post('/getMsgUserHuifu',router.getMsgUserHuifu);
app.post('/getMsgUserList',router.getMsgUserList);
/*个人用户*/

//错误页
app.get('/error',function(req,res){
    res.render('error',{page:'error'});
});
/*后台管理*/
app.get("/system",function(req,res){
    res.redirect('/system/index.html');
});
app.post('/system/login',router.systemLogin);
app.post('/system/getSystemMenu',router.getSystemMenu);
app.post('/system/getSystemEditMenu',router.getSystemEditMenu);
app.post('/system/getBooks',router.getBooks);
app.post('/system/getAllBookInfo',router.getAllBookInfo);
app.post('/system/getSubCate',router.getSubCate);
app.post('/system/setAddBook',router.setAddBook);
app.post('/system/getAuthors',router.getAuthors);
app.post('/system/setAddAuthor',router.setAddAuthor);
app.post('/system/authorUpdateImg',router.authorUpdateImg);
app.post('/system/setEditAuthor',router.setEditAuthor);
app.post('/system/removeAuthor',router.removeAuthor);
app.post('/system/BookUpdateImg',router.BookUpdateImg);
app.post('/system/removeBook',router.removeBook);
app.post('/system/setEditBook',router.setEditBook);
app.post('/system/getSelectBooks',router.getSelectBooks);
app.post('/system/getChapters',router.getChapters);
app.post('/system/setAddChapter',router.setAddChapter);
app.post('/system/setEditChapter',router.setEditChapter);
app.post('/system/removeChapter',router.removeChapter);
app.post('/system/setAddMenuOne',router.setAddMenuOne);
app.post('/system/removeSystemMenu',router.removeSystemMenu);
app.post('/system/setAddMenuTwo',router.setAddMenuTwo);
app.post('/system/editSystemMenu',router.editSystemMenu);
app.post('/sysDoExit',router.sysDoExit);
app.post('/system/getLogin',router.getLogin);
/*后台管理*/

//退出登录
app.get('/exit',router.doExit);
//中间件，错误页
app.use(function(req,res){
    res.render('error',{page:'error'});
});
app.listen(8080,function(){
    console.log('test running at http://localhost:8080');
});